package com.weihua.flow;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;
import org.apache.hadoop.mapreduce.lib.input.FileInputFormat;
import org.apache.hadoop.mapreduce.lib.output.FileOutputFormat;

import java.io.IOException;

public class FlowCountDriver {
    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        // 1、创建提交任务的对象job;
        Configuration conf = new Configuration();
        Job job = Job.getInstance(conf);

        // 2、设置加载jar包的位置
        job.setJarByClass(FlowCountDriver.class);

        // 3、设置Mapper类的子类名称;
        job.setMapperClass(FlowCountMapper.class);

        // 4、设置Reducer类的子类名称;
        job.setReducerClass(FlowCountReducer.class);

        // 5、设置Mapper类输出的数据:
        job.setMapOutputKeyClass(Text.class);
        job.setMapOutputValueClass(FlowBean.class);

        // 6、设置Reducer类输出的数据类型;
        job.setOutputKeyClass(Text.class);
        job.setOutputValueClass(FlowBean.class);

        // 7、数据源及输出结果文件的存储路径;
        FileInputFormat.setInputPaths(job, new Path("hdfs://10.0.0.50:8020/fuxi/flowcount/input"));
        FileOutputFormat.setOutputPath(job, new Path("hdfs://10.0.0.50:8020/fuxi/flowcount/output"));

        // 8、提交任务
        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);
    }
}
